
//获取地址栏参数
function getParameter(param){
   		var query = window.location.search;
   		var iLen = param.length;
   		var iStart = query.indexOf(param);
   		if (iStart == -1)
   			return "";
   		iStart += iLen + 1;
   		var iEnd = query.indexOf("&", iStart);
   		
   		if (iEnd == -1)
   			return query.substring(iStart);
   		return query.substring(iStart, iEnd);
 }
/*
 * 分享成功之后调用的方法
 * @param
 * shareType----分享类型，0代表分享给朋友，1代表分享到朋友圈
 * shareSource--分享来源
 * shareId------分享ID
 */
function shareRecord(shareType,shareSource,shareId){
	var localURL = window.location.href;
	 $.ajax({
			url:_argumentsObj.globalPath+"/v1/lenovo/weChat/shareRecord.html",
			dataType:"json",
			type:"post",
			data:{
				shareType:shareType,
				shareUrl:localURL,
				shareId:shareId,
				shareSource:shareSource
			},
			success:function(data){
				if(data.values!=''){
					_argumentsObj.playTimes = data.values.remainDrawNumber;
					_argumentsObj.shareCount = data.values.shareNumber;
				}
			},
			error:function(){
				//console.log("服务器异常");
				//如果此处无响应8.4版本应该跳转到车主认证页面
			}
		})
}



//更新验证码图片
function changeImg(id){  
    var imgSrc = $("#"+id);    
    var src = _argumentsObj.globalPath+"/v1/anon/user/create/verifyCode.html";
    imgSrc.attr("src",chgUrl(src));    
}
/*
 * 时间戳    
*为了使每次生成图片不一致，即不让浏览器读缓存，所以需要加上时间戳 
*
*/   
function chgUrl(url){
  var timestamp = (new Date()).valueOf();    
  var urlurl = url.substring(0,14);    
  if((url.indexOf("&")>=0)){    
      urlurl = url + "×tamp=" + timestamp;    
  }else{    
      urlurl = url + "?timestamp=" + timestamp;    
  }    
  return urlurl;    
}
/*
 * 获取短信验证码方法
 */
var checkGetVeryCode = true;
var seconds = null;
function getVerCode(){
	//记录点击事件
	clickListener(_argumentsObj.source,"h1-24","获取短信验证码按钮");
	if(!checkGetVeryCode){
		return;
	}
	 var phone=document.getElementById("phone").value;
	 var imgVeryCode = $("#imgVeryCodeInp").val();
	 var myreg = /^(((13[0-9]{1})|(14[0-9]{1})|(15[0-9]{1})|(17[0-9]{1})|(18[0-9]{1})|(19[0-9]{1}))+\d{8})$/;
	 if(!myreg.test(phone)||phone==""){
		 $(".alertErrorTip").show();
		 $(".alertErrorTip .errorTipWord").show();
		 $(".alertErrorTip .errorTipWord").html("请填写真实且准确的手机号。");
		 return
	 }
	 if(imgVeryCode==""){
		 $(".alertErrorTip").show();
		 $(".alertErrorTip .errorTipWord").show();
		 $(".alertErrorTip .errorTipWord").html("请输入图形验证码");
		 return
	 }
	checkGetVeryCode = false;
	 $.post(_argumentsObj.globalPath+"/v1/lenovo/activate/shortMessage.html",{phone:phone,imgVeryCode:imgVeryCode},function(data){
		 if(data.result=="ok"){
			 $(".alertErrorTip").show();
			 $(".alertErrorTip .errorTipWord").show();
	   		 $(".alertErrorTip .errorTipWord").html("短信验证码发送成功!");
	   	  	$("#getVeryCode").html("60s");
	   		seconds = setInterval(function(){
	   	   		var currentSecond = parseInt($("#getVeryCode").html());
	   	   		if(currentSecond==0){
	   	   			$("#getVeryCode").html("获取验证码");
	   	   			clearInterval(seconds);
	   	   			checkGetVeryCode = true;
	   	   		}else{
	   	   			$("#getVeryCode").html((currentSecond-1)+"s");
	   	   		}
	   	   	},1000);
		 }else{
			 $(".alertErrorTip").show();
			 $(".alertErrorTip .errorTipWord").show();
	   		 $(".alertErrorTip .errorTipWord").html(data.errormsg);
	   		changeImg('imgObj1');
	   		checkGetVeryCode = true;
		 }
	 });
};
//信息录入成功后
function checkInfo(){
	  var phone=document.getElementById("phone").value;
	  var veryCode=document.getElementById("veryCode").value;
	  var checkFalse = [];
	  var myreg = /^(((13[0-9]{1})|(14[0-9]{1})|(15[0-9]{1})|(17[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
	  var countFale = 0;
	  var tempTip = "";
	  var errorTip = ['姓名','手机号','验证码'];
	  if(!myreg.test(phone)||phone==""){
		  tempTip = "请填写真实且准确的手机号码。";
		  countFale++;
		  checkFalse.push(1);
	  }
	  if(veryCode==""){
		  tempTip = "请填写验证码。";
		  countFale++;
		  checkFalse.push(2);
	  }
	  if(countFale==1){
		  alert(tempTip);
		  return false;
	  }else if(countFale>1){
		  tempTip = "";
		  $.each(checkFalse,function(i,p){
			  if(i!=checkFalse.length-2){
					tempTip += errorTip[p]+"、";
				}else{
					tempTip+= errorTip[p]+"及";
				}
		  });
		  tempTip = tempTip.substring(0,tempTip.length-1);
		  tempTip+="有误。";
		  $(".alertErrorTip").show();
		  $(".alertErrorTip .errorTipWord").show();
	   	 $(".alertErrorTip .errorTipWord").html(tempTip);
		  return false;
	  }
	  
	  var ulr="";
	  var dataArgument = {
	   			phone:phone,
	   			code:veryCode,
	   	 };

	  return dataArgument;
}	

//关闭录入手机号弹窗
function closeAlert(){
	$("#phone").val("");
	$("#imgVeryCodeInp").val("");
	$("#veryCode").val("");
	$(".infoAlert").hide();
	$('body').removeClass("body-fixed");
}
//关闭错误提示弹窗
function closeErrorTip(el){
	if(_argumentsObj.followStatus==0&&_argumentsObj.sourcePage==0){
		window.location.reload();
	}
	if($(el).attr("data-canShare")==1){
		$(".indexShare").show();
		$(el).attr("data-canShare",0)
	}
	$(".alertErrorTip").hide();
	$(".alertErrorTipContent>div").hide();
}
